package controllers;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import models.COPSTemp;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.Query;

public class UploadConnect {
	int iROWS;
	Boolean hasEntries;

	
	
	/**
	 * @return datatable
	 * @author Chaiyan Chaiyachok
	 * @since  2012/7/25 : 16:00
	 */
	public List<HashMap<String, Object>> getFile(String _id) {
		List<HashMap<String, Object>> objList = new LinkedList<HashMap<String, Object>>();
		Objectify ofy = ObjectifyService.begin();
		
		
		 UserService userService = UserServiceFactory.getUserService();
		 User user = userService.getCurrentUser();
		   
		try {
			Query<COPSTemp> q = ofy.query(COPSTemp.class).filter("email",user.getEmail().toString());
			for (COPSTemp f : q.fetch()) {
				HashMap<String, Object> itemMap = new HashMap<String, Object>();
				itemMap.put("TopID", f.getTempPicKey());
				hasEntries = true;
				objList.add(itemMap);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return objList;
	}

}
